from __future__ import annotations

from dataclasses import dataclass


@dataclass
class SoldierPileDesign:
    embed_depth_m: float
    max_moment_kNm: float
    max_shear_kN: float
    note: str


def design_soldier_pile(active_pressure_kPa: float, excavation_depth_m: float, pile_spacing_m: float = 1.5) -> SoldierPileDesign:
    """支护桩抗弯与入土深度简化估算（等三角形压力）。"""

    H = excavation_depth_m
    p_max = active_pressure_kPa
    resultant = 0.5 * p_max * H  # kN/m
    lever = H / 3.0
    M = resultant * lever * pile_spacing_m
    V = resultant * pile_spacing_m
    embed = 0.4 * H
    return SoldierPileDesign(embed_depth_m=embed, max_moment_kNm=M, max_shear_kN=V, note="经验估算，需弹性地基梁复核")


@dataclass
class AnchorDesign:
    design_tension_kN: float
    length_m: float
    diameter_mm: int
    spacing_m: float
    note: str


def design_soil_anchor(required_tension_kN: float, bond_strength_kPa: float, safety_factor: float = 2.0, spacing_m: float = 1.5) -> AnchorDesign:
    """土钉/锚杆设计：长度按 T/(πdτ) 给出；直径按承载力满足并取最小。"""

    import math
    T = required_tension_kN * safety_factor
    d = 0.025  # m 起算
    tau = bond_strength_kPa / 1000.0
    L = max(2.0, T / max(1e-6, math.pi * d * tau))
    dia_mm = int(d * 1000)
    return AnchorDesign(design_tension_kN=T, length_m=L, diameter_mm=dia_mm, spacing_m=spacing_m, note="需抗拔与位移验算")


